package com.polaris.live.popup.party

import android.content.Context
import com.blankj.utilcode.util.StringUtils
import com.bumptech.glide.Glide
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.autoDp
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.PopupExitMemberBinding
import com.polaris.live.translation.R.string
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.transformRounded

/**
 * ExitMemberPopup 退出房间提示
 *
 * @author Created by 天晴 on 2024/3/8 19:18
 * @since 1.0.0
 **/
class ExitMemberPopup(
    context: Context,
    private val cover: String,
    private val roomName: String,
    private val onOk: () -> Unit,
) : CenterPopupView(context) {

    private lateinit var mBinding: PopupExitMemberBinding
    override fun getImplLayoutId(): Int {
        return R.layout.popup_exit_member
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupExitMemberBinding.bind(popupImplView)
        mBinding.cancel.setOnSingleClickListener {
            dismiss()
        }
        mBinding.cancel.setOnSingleClickListener {
            dismiss()
        }
        mBinding.confirm.setOnSingleClickListener {
            dismiss()
            onOk.invoke()
        }

        mBinding.apply {
            tvMessage.text = StringUtils.getString(string.exit_member_tips)
            Glide.with(context)
                .load(ImageUtils.imgPath(cover))
                .transformRounded(6.autoDp)
                .into(roomImg)
            tvRoomName.text = roomName
        }
    }

    companion object {

        fun show(
            context: Context,
            cover: String,
            roomName: String,
            onOk: () -> Unit,
        ) {
            XPopup.Builder(context)
                .isViewMode(false)
                .hasShadowBg(true)
                .moveUpToKeyboard(false)
                .isDestroyOnDismiss(true)
                .asCustom(ExitMemberPopup(context, cover, roomName, onOk))
                .show()
        }
    }
}